from usb2gpio import usb_device
import ctypes

# DevHandle = 555820895
def init():
    DevHandles = (ctypes.c_int * 20)()
    DevHandle = 0
    # Scan device
    ret = usb_device.USB_ScanDevice(ctypes.byref(DevHandles))
    if ret == 0:
        print("No device connected!")
        exit()
    else:
        print("Have %d device connected!" % ret)
        DevHandle = DevHandles[0]  # 选择设备0
    # Open device
    ret = usb_device.USB_OpenDevice(DevHandle)
    if bool(ret):
        print("Open device success!")
    else:
        print("Open device faild!")
        exit()
    return DevHandle